********************************************************************************
*
*	Lee-Liou 
*   Where You Work Is Where You Stand: 
*   A Firm-Based Framework for Understanding Trade Opinion
*	Manuscript Tables & Figures Code
*	First Written 1/20/2015
*	Last Modified 1/19/2022
*
********************************************************************************

*	Change path based on the computer name:

use "JGSS 2008.dta", clear

eststo clear

set more off

*	Create industry dummies for industry fixed effects 
tab industry, gen(ind_dum) 
	*NB: Agriculture will be reference industry
	
*	Table 2 (Testing H1)
********************************************************************************

set more off

*	Model1: Base Model
eststo tab1_h1: reg trade collgrad emp_glob   ///
   female age union 	///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)

*	Model2: Base Model + com_disadv
eststo tab1_h1a: reg trade collgrad  emp_glob   ///
   female age union comp_disadv ///
   , cluster(industry)

*	Model3: Base Model + localism
eststo tab1_h1b: reg trade collgrad  emp_glob   ///
   female age union localism ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)

*	Model 4: Base Model + LDP - 
eststo tab1_h1c: reg trade collgrad  emp_glob   ///
   female age union LDP   ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
*	Model 5: Base Model + occupational controls
eststo tab1_h1d: reg trade collgrad  emp_glob   ///
   female age union  ///
 task_routine task_offshorability ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
*	Model 6: base Model + Attitudinal controls
eststo tab1_h1e: reg trade collgrad  emp_glob glob_workers  ///
   female age union redistribution cosmo_avg jobloss_prob	///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry) 
 
esttab tab1_h1 tab1_h1a tab1_h1b tab1_h1c tab1_h1d tab1_h1e  ///
 using "tab1_reduced_OLS_fe_clust.tex", ///
	replace label nogap  b(2) se  /// 
	star(* 0.10 ** 0.05 *** 0.01)  ///
	ti(Firm Characteristics and Support for Protection (Industry Fixed Effects)) 

 
*	Table 3 (Testing H2)
********************************************************************************
set more off  

*	Model1: emp_glob X comp_disadv
eststo tab2_h2_ind: xi: reg trade i.emp_glob*i.comp_disadv collgrad  ///
	 female age union , cluster(industry) 


*	Model2: emp_glob X collgrad
eststo tab2_h2_skill: xi: reg trade i.emp_glob*i.collgrad  ///
	 female age union   ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
  
*	Model 3: emp_glob X task_offshorability interaction
eststo tab2_offshore: reg trade  collgrad i.emp_glob##c.task_offshorability task_routine  ///
  female age union    ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
  
*	Model 4: task_routine X task_offshorability interaction 
eststo tab2_routine_offshore: reg trade emp_glob collgrad c.task_routine##c.task_offshorability  ///
  female age  union ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
*	Model 5: task_routine X task_offshorability interaction for domestic employers 
eststo tab2_routine_offshore_0: reg trade collgrad c.task_routine##c.task_offshorability  ///
  female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if emp_glob==0, cluster(industry)

*	Model 6: task_routine X task_offshorability interaction for globalized employers  
eststo tab2_routine_offshore_1: reg trade collgrad c.task_routine##c.task_offshorability  ///
  female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if emp_glob==1, cluster(industry)
  
esttab tab2_h2_ind  tab2_h2_skill tab2_offshore tab2_routine_offshore ///
 tab2_routine_offshore_0 tab2_routine_offshore_1 ///
 using "tab2_reduced_OLS_fe_clust.tex", ///
	replace label nogap  b(2) se  /// 
	star(* 0.10 ** 0.05 *** 0.01)  ///
	ti(Conditional Effects of Firm Productivity (Industry Fixed Effects))

  
eststo clear

*	Table 4 (Hypothesis 3 Testing)
********************************************************************************
set more off
 
*	Model1: emp_glob X jobloss_prob
eststo tab3_h3_1: reg trade i.emp_glob##c.jobloss_prob collgrad ///
   female age union   ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
 
*	Model2: emp_glob X temp_worker

eststo tab3_h3_2: xi: reg trade i.emp_glob*i.temp_worker collgrad ///
   female age union ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry) 
  
 
*	Model3: emp_glob X mgmt
eststo tab3_h3_3: xi: reg trade i.emp_glob*i.mgmt_dum collgrad ///
   female age union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)


 * Figure 1 
* Base Model:
*	No interactions  
 *******************************************************************************
set seed 8181983	

graph set window fontface "CMU Serif"

reg trade collgrad  emp_glob  ///
  female age  union  ///
 ind_dum2-ind_dum21, cluster(industry)

margins, at(emp_glob=(0 1) ///
 (median) collgrad female  union age ///
 (means) ) post
 
*	NB: need to plot the SEs as error bars, not 95% CIs to show statistical significance 
marginsplot, x(emp_glob) recast(scatter) ///
 xscale(range(-0.5(0.5)1.5) titlegap(4)) xtitle("", size(vlarge)) ///
 xlabel(0 `" "Domestic" "Employer" "' 1 `" "Globalized" "Employer" "', labsize(vlarge) nogrid notick) ///
 scheme(s2color) graphregion(color(white)) ///
 ysca(titlegap(4)) ytitle("Protection: Predicted Value", size(vlarge)) ///
 yscale(range(3.8 4.8) titlegap(4)) ylabel(3.8(0.2)4.8) ///
 ylabel(, labsize(vlarge)) ///
 title("Employer Type", color(black) size(vlarge)) level(`=round((normal(1)-normal(-1))*100,.01)')
 
graph export "MS_reduced_base_OLS_fe.png", replace

*	Compare to size of collgrad effect
reg trade collgrad  emp_glob  ///
 female age  union  ///
 ind_dum2-ind_dum21, cluster(industry)

margins, at(collgrad=(0 1) ///
 (median) emp_glob female  union age ///
 (means) ) post

marginsplot, x(collgrad) recast(scatter) ///
 xscale(range(-0.5(0.5)1.5) titlegap(4)) xtitle("", size(vlarge)) ///
 xlabel(0 `" "Non-" "Graduate" "' 1 `" "College" "Graduate" "', labsize(vlarge)  nogrid notick) ///
 scheme(s2color) graphregion(color(white)) ///
 ysca(titlegap(4)) ytitle("Protection: Predicted Value", size(vlarge)) ///
 yscale(range(3.8 4.8) titlegap(4)) ylabel(3.8(0.2)4.8) ///
 ylabel(, labsize(vlarge)) ///
 title("Skill Level", color(black) size(vlarge)) level(`=round((normal(1)-normal(-1))*100,.01)')
 
graph export "MS_reduced_base_collgrad_OLS_fe.png", replace
 
*	Compare to size of sector effect
********************************************************************************
*	NB: Cannot use industry fixed effects due to collinearity with comp_disadv
********************************************************************************

reg trade collgrad  emp_glob  comp_disadv ///
 female age  union, cluster(industry)

margins, at(comp_disadv=(0 1) ///
 (median) emp_glob collgrad female  union age ///
 (means) ) post

marginsplot, x(comp_disadv) recast(scatter) ///
 xscale(range(-0.5(0.5)1.5) titlegap(4)) xtitle("", size(vlarge)) ///
 /*	double quotes in next line allow line breaks in axis labels*/ ///
 xlabel(0 `" "Comparative" "Advantage" "' 1 `" "Comparative" "Disadvantage" "', labsize(vlarge) nogrid notick) ///
 scheme(s2color) graphregion(color(white)) ///
 ysca(titlegap(4)) ytitle("Protection: Predicted Value", size(vlarge)) ///
 yscale(range(3.8 4.8) titlegap(4)) ylabel(3.8(0.2)4.8) ///
 ylabel(, labsize(vlarge)) ///
 title("Sector Competitiveness", color(black) size(vlarge)) level(`=round((normal(1)-normal(-1))*100,.01)')
 
graph export "MS_reduced_base_comp_disadv_OLS_fe.png", replace

********************************************************************************
*	Figure 2 
 * NNT hypothesis 2:
*	*emp_glob interaction  
******************************************************************************** 

********************************************************************************
*	emp_glob*comp_disadv interaction  
********************************************************************************
 
reg trade emp_glob##comp_disadv collgrad ///
   female age  union, cluster(industry)
 
/*
Note that have to set confidence levels at SEs rather than estimate CIs so that 
error bars don't overlap and give the (mistaken) impression of lack of 
significant separation between estimates. 
*/ 
margins, at(comp_disadv=0 emp_glob=0 (median) collgrad  ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(CD0_X_EG0, replace)
 
margins, at(comp_disadv=0 emp_glob=1 (median) collgrad  ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(CD0_X_EG1, replace) 
 
margins, at(comp_disadv=1 emp_glob=0 (median) collgrad ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(CD1_X_EG0, replace)

margins, at(comp_disadv=1 emp_glob=1 (median) collgrad ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(CD1_X_EG1, replace)  

*	Domestic Firms
combomarginsplot CD0_X_EG0 CD1_X_EG0, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Advantaged" 2 "Disadvantaged", labsize(large)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Domestic Employers", size(vlarge) color(black)) ///
name(EG0_X_CD_OLS_fe, replace) 

graph save "EG0_X_CD_OLS_fe", replace

*	Globalized Firms
combomarginsplot CD0_X_EG1 CD1_X_EG1, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Advantaged" 2 "Disadvantaged", labsize(large)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Globalized Employers", size(vlarge) color(black)) ///
name(EG1_X_CD_OLS_fe, replace)

graph save "EG1_X_CD_OLS_fe", replace

*	Combined
graph combine "EG0_X_CD_OLS_fe" "EG1_X_CD_OLS_fe", ycommon ///
title("Sector Competitiveness", color(black)) scheme(s2color) graphregion(color(white))

graph export "MS_reduced_comp_disadv_X_emp_glob_OLS_fe.png", replace

********************************************************************************
*	emp_glob*collgrad interaction
********************************************************************************

reg trade i.emp_glob##collgrad  ///
  female age  union  ///
 ind_dum2-ind_dum21, cluster(industry)
 
margins, at(collgrad=0 emp_glob=0 (median)   ///
 female  union age (means)) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(grad0_X_EG0, replace)
 
margins, at(collgrad=0 emp_glob=1 (median) ///
 female  union age (means)) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(grad0_X_EG1, replace)
 
margins, at(collgrad=1 emp_glob=0 (median)  ///
 female  union age (means)) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(grad1_X_EG0, replace)

margins, at(collgrad=1 emp_glob=1 (median) ///
 female  union age (means)) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(grad1_X_EG1, replace)  

*	Domestic Employers
combomarginsplot grad0_X_EG0 grad1_X_EG0, recast(scatter) ///
	xscale(range(0.5(0.5)2.5)) xlabel(1 "Non-Grads" 2 "Graduates", labsize(large)) xtitle("", size(vlarge)) ///
	ytitle("Protection: Predicted Value", size(vlarge)) ///
	ylabel(, labsize(vlarge)) ///
	xsca(titlegap(4))	/// *adds gap between title and labels
	scheme(s2color) graphregion(color(white)) ///
	title("Domestic Employers", size(vlarge) color(black)) ///
	name(EG0_X_grad_OLS_fe, replace)

graph save "EG0_X_grad_OLS_fe", replace
	
*	Globalized Employers
combomarginsplot grad0_X_EG1 grad1_X_EG1, recast(scatter) ///
	xscale(range(0.5(0.5)2.5)) xlabel(1 "Non-Grads" 2 "Graduates", labsize(large)) xtitle("", size(vlarge)) ///
	ytitle("Protection: Predicted Value", size(vlarge)) ///
	ylabel(, labsize(vlarge)) ///
	xsca(titlegap(4))	/// *adds gap between title and labels
	scheme(s2color) graphregion(color(white)) ///
	title("Globalized Employers", size(vlarge) color(black)) ///
	name(EG1_X_grad_OLS_fe, replace)

graph save "EG1_X_grad_OLS_fe", replace

*	Combined
graph combine "EG0_X_grad_OLS_fe" "EG1_X_grad_OLS_fe", ycommon ///
title("Skill Level", color(black)) scheme(s2color) graphregion(color(white))

graph export "MS_reduced_collgrad_X_emp_glob_OLS_fe.png", replace

********************************************************************************
*	Margins at mean values of task_routine:
********************************************************************************
set more off

*	Calculate margins for domestic only, and globalized only
 
reg trade emp_glob  collgrad c.task_routine##c.task_offshorability  ///
 female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if emp_glob==0, cluster(industry)
 
margins if emp_glob==0, at(task_offshorability=(-3.2(0.2)3.2) ///
 (median) emp_glob female  union age ///
 (means) task_routine ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(offshore_routine_EG0_mean_OLS_fe, replace)
 
reg trade emp_glob  collgrad c.task_routine##c.task_offshorability  ///
 female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if emp_glob==1, cluster(industry)
 
margins if emp_glob==1, at(task_offshorability=(-3.2(0.2)3.2) ///
 (median) emp_glob female  union age ///
 (means) task_routine ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(offshore_routine_EG1_mean_OLS_fe, replace)
 
*	Domestic employers only
marginsplot using "offshore_routine_EG0_mean_OLS_fe", x(task_offshorability) recast(line) ///
plotopts(lcolor(maroon)) ///
title("Domestic", color(black) size(vlarge)) ///
 ytitle("Protection: Predicted Value", size(vlarge)) ysc(titlegap(5)) ///
 ylabel(, labsize(vlarge)) ///
 xtitle("Task Offshorability", size(vlarge))  ///
 xlabel(, labsize(vlarge)) xsc(titlegap(5)) /// //use xsc option to create space between axis labels and axis title//
 scheme(s2color) graphregion(color(white)) ///
 recastci(rarea) ciopts(color(maroon%15)) ///
 name(offshore_routine_EG0_mean_OLS_fe, replace) 
 
graph save "offshore_routine_EG0_mean_OLS_fe", replace

*	Globalized employers only
marginsplot using "offshore_routine_EG1_mean_OLS_fe", x(task_offshorability) recast(line) ///
title("Globalized", color(black) size(vlarge)) ///
 ytitle("Protection: Predicted Value", size(vlarge)) ysc(titlegap(5)) ///
 ylabel(, labsize(vlarge)) ///
 xtitle("Task Offshorability", size(vlarge))  ///
 xlabel(, labsize(vlarge)) xsc(titlegap(5)) /// //use xsc option to create space between axis labels and axis title//
 scheme(s2color) graphregion(color(white)) ///
 recastci(rarea) ciopts(color(%15)) ///
 name(offshore_routine_EG1_mean_OLS_fe, replace) 
 
graph save "offshore_routine_EG1_mean_OLS_fe", replace

*	Combine domestic and globalized for comparison:
graph combine "offshore_routine_EG0_mean_OLS_fe" "offshore_routine_EG1_mean_OLS_fe", ycommon ///
title("Exposure to Offshoring at Mean Task Routineness", color(black)) rows(1) scheme(s2color) ///
graphregion(color(white))

graph export "MS_reduced_offshore_routine_mean_duo_OLS_fe.png", replace

********************************************************************************
*	Margins at mean values of task_offshorability:
********************************************************************************
set more off

*	Calculate margins for domestic only, and globalized only

reg trade emp_glob  collgrad c.task_routine##c.task_offshorability  ///
 female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if emp_glob==0, cluster(industry)
 
margins if emp_glob==0, at(task_routine=(1.2(0.2)8.6) ///
 (median) emp_glob  female  union age ///
 (means) task_offshorability ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(routine_offshore_EG0_mean_OLS_fe, replace)
 
reg trade emp_glob  collgrad c.task_routine##c.task_offshorability  ///
 female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if emp_glob==1, cluster(industry)
 
margins if emp_glob==1, at(task_routine=(1.2(0.2)8.6) ///
 (median) emp_glob female  union age ///
 (means) task_offshorability ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(routine_offshore_EG1_mean_OLS_fe, replace)
 

*	Domestic employers only
marginsplot using "routine_offshore_EG0_mean_OLS_fe", x(task_routine) recast(line) ///
plotopts(lcolor(maroon)) ///
title("Domestic", color(black) size(vlarge)) ///
 ytitle("Protection: Predicted Value", size(vlarge)) ysc(titlegap(5)) ///
 ylabel(, labsize(vlarge)) ///
 xtitle("Task Routineness", size(vlarge))  ///
 xlabel(1(1)9, labsize(vlarge)) xsc(titlegap(5)) /// //use xsc option to create space between axis labels and axis title//
 scheme(s2color) graphregion(color(white)) ///
 recastci(rarea) ciopts(color(maroon%15)) ///
 name(routine_offshore_EG0_mean_OLS_fe, replace) 
 
graph save "routine_offshore_EG0_mean_OLS_fe", replace

*	Globalized employers only
marginsplot using "routine_offshore_EG1_mean_OLS_fe", x(task_routine) recast(line) ///
title("Globalized", color(black) size(vlarge)) ///
 ytitle("Protection: Predicted Value", size(vlarge)) ysc(titlegap(5)) ///
 ylabel(, labsize(vlarge)) ///
 xtitle("Task Routineness", size(vlarge))  ///
 xlabel(1(1)9, labsize(vlarge)) xsc(titlegap(5)) /// //use xsc option to create space between axis labels and axis title//
 scheme(s2color) graphregion(color(white)) ///
 recastci(rarea) ciopts(color(%15)) ///
 name(routine_offshore_EG1_mean_OLS_fe, replace) 
 
graph save "routine_offshore_EG1_mean_OLS_fe", replace

*	Combine domestic and globalized for comparison:
graph combine "routine_offshore_EG0_mean_OLS_fe" "routine_offshore_EG1_mean_OLS_fe", ycommon ///
title("Task Routineness at Mean Offshorability", color(black)) rows(1) scheme(s2color) ///
graphregion(color(white))

graph export "MS_reduced_routine_offshore_mean_duo_OLS_fe.png", replace

******************************************************************************** 
*	Figure 3 
********************************************************************************

******************************************************************************** 
*	temp_worker*emp_glob interaction
********************************************************************************

reg trade i.emp_glob##temp_worker collgrad  ///
  female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
margins, at(temp_worker=0 emp_glob=0 (median) ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(temp0_X_EG0, replace)
 
margins, at(temp_worker=0 emp_glob=1 (median)  ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(temp0_X_EG1, replace)
 
margins, at(temp_worker=1 emp_glob=0 (median) ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(temp1_X_EG0, replace)

margins, at(temp_worker=1 emp_glob=1 (median) ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(temp1_X_EG1, replace)  
 
*	Permanent Employees 
combomarginsplot temp0_X_EG0 temp0_X_EG1, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Domestic" 2 "Globalized", labsize(vlarge)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Permanent Employees", size(vlarge) color(black)) ///
name(temp0_X_EG_OLS_fe, replace)

graph save "temp0_X_EG_OLS_fe", replace

*	Temporary Employees
combomarginsplot temp1_X_EG0 temp1_X_EG1, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Domestic" 2 "Globalized", labsize(vlarge)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Temporary Employees", size(vlarge) color(black)) ///
name(temp1_X_EG_OLS_fe, replace)

graph save "temp1_X_EG_OLS_fe", replace

*	Combined
graph combine "temp1_X_EG_OLS_fe" "temp0_X_EG_OLS_fe", ycommon ///
title("Temporary Work Status", color(black)) scheme(s2color) graphregion(color(white))

graph export "MS_reduced_emp_glob_X_temp_worker_OLS_fe.png", replace 


********************************************************************************
*job insecurity*emp_glob interaction
********************************************************************************

*	Dichotomizing 

recode jobloss_prob (1/2=0) (3/4=1), gen(job_notsafe)
	label var job_notsafe "At least `fairly likely' to lose job in next 12 months?"
	label values job_notsafe ny

reg trade emp_glob##job_notsafe collgrad   ///
 female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
margins, at(job_notsafe=0 emp_glob=0 (median) collgrad  ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(JNS0_X_EG0, replace)
 
margins, at(job_notsafe=0 emp_glob=1 (median) collgrad ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(JNS0_X_EG1, replace)
 
margins, at(job_notsafe=1 emp_glob=0 (median) collgrad  ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(JNS1_X_EG0, replace)

margins, at(job_notsafe=1 emp_glob=1 (median) collgrad ///
 female  union age (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(JNS1_X_EG1, replace)  

*	Job Secure 
combomarginsplot JNS0_X_EG0 JNS0_X_EG1, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Domestic" 2 "Globalized", labsize(vlarge)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Job Secure", size(vlarge) color(black)) ///
name(JNS0_X_EG, replace)

graph save "JNS0_X_EG_OLS_fe", replace

*	Job Not Secure
combomarginsplot JNS1_X_EG0 JNS1_X_EG1, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Domestic" 2 "Globalized", labsize(vlarge)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Job Not Secure", size(vlarge) color(black)) ///
name(JNS1_X_EG, replace) 

graph save "JNS1_X_EG_OLS_fe", replace

*	Combined
graph combine "JNS1_X_EG_OLS_fe" "JNS0_X_EG_OLS_fe", ycommon ///
title("Job Security", color(black)) scheme(s2color) graphregion(color(white))

graph export "MS_reduced_emp_glob_X_job_notsafe_OLS_fe.png", replace
********************************************************************************
*	mgmt*emp_glob interaction
********************************************************************************

*	Having a high-level manager position is another measure of skill level (besides education)

reg trade i.emp_glob##mgmt_dum collgrad   ///
  female age  union  ///
 ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
 
margins, at(mgmt_dum=0 emp_glob=0 (median) ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(mgmt_self0_X_EG0, replace)
 
margins, at(mgmt_dum=0 emp_glob=1 (median) ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(mgmt_self0_X_EG1, replace)
 
margins, at(mgmt_dum=1 emp_glob=0 (median) ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(mgmt_self1_X_EG0, replace)

margins, at(mgmt_dum=1 emp_glob=1 (median) ///
 female  union age collgrad (means) ) ///
 level(`=round((normal(1)-normal(-1))*100,.01)') saving(mgmt_self1_X_EG1, replace)  
 
*	Non-Executives 
combomarginsplot mgmt_self0_X_EG0 mgmt_self0_X_EG1, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Domestic" 2 "Globalized", labsize(vlarge)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Non-Managers", size(vlarge) color(black)) ///
name(mgmt_self0_X_EG_OLS_fe, replace)

graph save "mgmt_self0_X_EG_OLS_fe", replace

*	Executives
combomarginsplot mgmt_self1_X_EG0 mgmt_self1_X_EG1, recast(scatter) ///
xscale(range(0.5(0.5)2.5)) xlabel(1 "Domestic" 2 "Globalized", labsize(vlarge)) xtitle("", size(vlarge)) ///
ytitle("Protection: Predicted Value", size(vlarge)) ///
ylabel(, labsize(vlarge)) ///
xsca(titlegap(4))	/// *adds gap between title and labels
scheme(s2color) graphregion(color(white)) ///
title("Managers", size(vlarge) color(black)) ///
name(mgmt_self1_X_EG_OLS_fe, replace)

graph save "mgmt_self1_X_EG_OLS_fe", replace

*	Combined
graph combine "mgmt_self0_X_EG_OLS_fe" "mgmt_self1_X_EG_OLS_fe", ycommon ///
title("Job Role", color(black)) scheme(s2color) graphregion(color(white))

graph export "MS_reduced_emp_glob_X_mgmt_self_OLS_fe.png", replace


********************************************************************************
*Table 5 
*Altonji and Poet Tests* 
********************************************************************************
********************************************************************************
*Altonji Tests 
********************************************************************************
** generate control variable groups for full models **
local reduced_controls collgrad female age union
local baseline_controls collgrad female age union glob_workers redistribution cosmo_avg jobloss_pro 
local baseline_controls2 collgrad female age union glob_workers redistribution cosmo_avg jobloss_pro task_offshorability task_routine

** preserve these groupings**
preserve

** run full and restricted models to generate coefficients for ratio calculation using reduced_controls ** 

xi: reg trade emp_glob `reduced_controls'  ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
predict hat if e(sample), xb
gen beta2=_b[emp_glob]

xi: reg trade emp_glob  ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if missing(hat)!=1, cluster(industry)
gen beta1=_b[emp_glob] if missing(hat)!=1

gen diff1_2 = beta2/(beta1-beta2)

drop hat

** run full and restricted models to generate coefficients for ratio calculation using baseline_controls ** 

xi: reg trade emp_glob `baseline_controls'  ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
predict hat if e(sample), xb
gen beta4=_b[emp_glob]

xi: reg trade emp_glob  ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if missing(hat)!=1, cluster(industry)
gen beta3=_b[emp_glob] if missing(hat)!=1

gen diff3_4 = beta4/(beta3-beta4)


drop hat

** run full and restricted models to generate coefficients for ratio calculation using baseline_controls2 ** 

xi: reg trade emp_glob `baseline_controls2'  ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21, cluster(industry)
predict hat if e(sample), xb
gen beta6=_b[emp_glob]

xi: reg trade emp_glob  ind_dum2 ind_dum3 ind_dum4 ind_dum5 ind_dum6 ind_dum7 ind_dum8 ind_dum9 ///
 ind_dum10 ind_dum11 ind_dum12 ind_dum13 ind_dum14 ind_dum15 ind_dum16 ///
 ind_dum17 ind_dum18 ind_dum19 ind_dum20 ind_dum21 if missing(hat)!=1, cluster(industry)
gen beta5=_b[emp_glob] if missing(hat)!=1

gen diff5_6 = beta6/(beta5-beta6)

drop hat


** calculate ratios ** 

sum diff*

********************************************************************************
*POET tests 
********************************************************************************
  *	baseline controls:
  poet trade collgrad union ind_dum*, ///
 treat(emp_glob) other(female age)

 *	baseline2 controls 
 poet trade collgrad union cosmo_avg redistribution glob_workers ind_dum*, ///
 treat(emp_glob) other(female age jobloss_pro )


 *	baseline3 controls (including task attributes)
poet trade collgrad union task_offshorability task_routine cosmo_avg glob_workers redistribution ind_dum*, ///
 treat(emp_glob) other(female age jobloss_pro)
  
